export function compareTimestamp(timestamp) {
	const currentTime = new Date().getTime();
	const timeDiff = currentTime - timestamp;

	if (timeDiff < 60000) {
		return '1分钟内';
	} else if (timeDiff < 3600000) {
		return Math.floor(timeDiff / 60000) + '分钟';
	} else if (timeDiff < 86400000) {
		return Math.floor(timeDiff / 3600000) + '小时';
	} else if (timeDiff < 2592000000) {
		return Math.floor(timeDiff / 86400000) + '天';
	} else if (timeDiff < 7776000000) {
		return Math.floor(timeDiff / 2592000000) + '月';
	} else {
		return null;
	}
}


export function gotoHome() {
	uni.showModal({
		title: "提示",
		content: "页面有误将返回首页",
		showCancel: false,
		success: (res) => {
			if (res.confirm) {
				uni.reLaunch({
					url: "/pages/index/index"
				})
			}
		}
	})
}

export function goSource(textToCopy) {
	if (textToCopy) {
		if (process.env.UNI_PLATFORM === 'h5') {
			window.location.href = textToCopy;
		} else {
			uni.setClipboardData({
				data: textToCopy, // 要拷贝到剪贴板的数据  
				success: function() {
					console.log('拷贝成功');
					uni.showToast({
						title: '拷贝成功',
						icon: 'success',
						duration: 1000
					});
				},
				fail: function(err) {
					console.error('拷贝失败:', err);
					uni.showToast({
						title: '拷贝失败',
						icon: 'none',
						duration: 1000
					});
				}
			});
		}
	} else {
		console.error('No valid link found');
	}
}